package test.list;

import test.bean.Event;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.Date;

public class TimeComparator implements Comparator<Event> {
    //private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
    private static final DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Override
    public int compare(Event e1, Event e2) {
        Date time1;
        Date time2;
        try {
            time1 = formatter.parse(e1.getEventTime());
            time2 = formatter.parse(e2.getEventTime());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return time1.compareTo(time2);
    }
}
